package com.gpj.learn.springmvc.java.init;

import com.gpj.learn.springmvc.java.config.SpringMvcConfig;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

/**
 * @className CustomWebApplicationInitializer
 * @description TODO
 * @author GPJ
 * @date 2020/3/14 15:52
 * @version 1.0
 **/
public class CustomWebApplicationInitializer implements WebApplicationInitializer {

    @Override
    public void onStartup(javax.servlet.ServletContext servletContext) throws ServletException {
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        context.register(SpringMvcConfig.class);

        final DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
        final ServletRegistration.Dynamic registration = servletContext.addServlet("app", dispatcherServlet);
        registration.setLoadOnStartup(1);
        registration.addMapping("*.do");
    }
}
